package com.booking.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booking.common.dto.PageReq;
import com.booking.common.dto.PageResp;
import com.booking.common.utils.ConvertUtils;
import com.booking.controller.model.req.homestay.HomestayQueryReq;
import com.booking.dao.entity.HomestayInfo;
import com.booking.dao.mapper.HomestayInfoMapper;
import com.booking.dao.service.HomestayInfoService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

/**
 * @author Qikai.Lin
 * @date 2023/4/21
 */
@Service
public class HomestayInfoServiceImpl extends ServiceImpl<HomestayInfoMapper, HomestayInfo> implements HomestayInfoService {
    @Override
    public PageResp<HomestayInfo> getPage(PageReq<HomestayQueryReq> request) {
        HomestayQueryReq condition = request.getCondition();
        QueryWrapper<HomestayInfo> pageQueryWrapper = new QueryWrapper<>();
        pageQueryWrapper.like(Strings.isNotEmpty(condition.getName()), "name", condition.getName());
        pageQueryWrapper.like(Strings.isNotEmpty(condition.getAddress()), "address", condition.getAddress());
        Page<HomestayInfo> homestayInfoPage = new Page<>(request.getCurrent(), request.getSize());
        Page<HomestayInfo> page = this.page(homestayInfoPage, pageQueryWrapper);
        return ConvertUtils.convert(PageResp.class, page);
    }
}
